﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace xiketang.com.LotteryPro
{
    public partial class FrmMain : Form
    {

        //创建选号器对象
        private Selector newSelector = new Selector();

        //定义成员变量，用于存储选号器产生的随机数集合
        List<string> randomNum = null;

        //存储 开始选号 的次数
        int orderRandNum = 0;
        public FrmMain()
        {
            InitializeComponent(); 
            this.btnSelect.Enabled = false;

        }

        #region  拖动和关闭窗体

        private Point mouseOff;//鼠标移动位置变量
        private bool leftFlag;//标签是否为左键
        private void FrmMain_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                leftFlag = true;                  //点击左键按下时标注为true;
            }
        }
        private void FrmMain_MouseMove(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                Location = mouseSet;
            }
        }
        private void FrmMain_MouseUp(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                leftFlag = false;//释放鼠标后标注为false;
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #endregion

        //启动选号
        private void btnStart_Click(object sender, EventArgs e)
        {
            this.timerCreateNum.Start();
            this.btnSelect.Enabled = true;
            this.btnStart.Enabled = false;

        }
        //定时器：每隔50ms调用一次
        private void timerCreateNum_Tick(object sender, EventArgs e)
        {
            randomNum = newSelector.CreateRandomNum();
            this.lblNum1.Text = randomNum[0];
            this.lblNum2.Text = randomNum[1];
            this.lblNum3.Text = randomNum[2];
            this.lblNum4.Text = randomNum[3];
            this.lblNum5.Text = randomNum[4];
            this.lblNum6.Text = randomNum[5];
            this.lblNum7.Text = randomNum[6];

        }

        //开始选号
        private void btnSelect_Click(object sender, EventArgs e)
        {
            this.timerCreateNum.Stop();
            this.btnSelect.Enabled = false;
            this.btnStart.Enabled = true;
            //点击选择按钮后
            //创建双色球对象
            DoubleChromosphere dc = new DoubleChromosphere()
            {
                Numbers = this.randomNum
            };
            //添加到选号池
            this.newSelector.SelectedNums.Add(dc);

            //显示号码
            string num = string.Empty;
            

            foreach (string s in this.randomNum)
            {
                num += s + " ";
            }

            //显示号码
            orderRandNum++;
            num = "第" + orderRandNum + "组："+ num;
            this.lbNumberList.Items.Add(num);
        }
        //清除
        private void btnDel_Click(object sender, EventArgs e)
        {
            this.newSelector.SelectedNums.Clear();
            this.lbNumberList.Items.Clear();
            orderRandNum = 0;
        }       
        //确认购买
        private void btnConfirm_Click(object sender, EventArgs e)
        {

        }
        
    }
}
